// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.util;

import zombie.iso.Vector3;

public class RaySphereIntersectCheck {
    static Vector3 toSphere = new Vector3();
    static Vector3 dirNormal = new Vector3();

    public static boolean intersects(Vector3 origin, Vector3 dirAndLength, Vector3 sphereCentre, float sphereRadius) {
        sphereRadius *= sphereRadius;
        dirNormal.x = dirAndLength.x;
        dirNormal.y = dirAndLength.y;
        dirNormal.z = dirAndLength.z;
        dirNormal.normalize();
        toSphere.x = sphereCentre.x - origin.x;
        toSphere.y = sphereCentre.y - origin.y;
        toSphere.z = sphereCentre.z - origin.z;
        float float0 = toSphere.getLength();
        float0 *= float0;
        if (float0 < sphereRadius) {
            return false;
        } else {
            float float1 = toSphere.dot3d(dirNormal);
            if (float1 < 0.0F) {
                return false;
            } else {
                float float2 = sphereRadius + float1 * float1 - toSphere.getLength();
                return (double)float2 >= 0.0;
            }
        }
    }
}
